﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using extremeEvents;

namespace BackofficeExtremeEvents.Categorias
{
    public partial class ListarCategorias : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
           // if (e.!= "-1")
           // {
                Session["id_categoria"] = GridView1.DataKeys[int.Parse(e.CommandArgument.ToString())].Value;
                if (e.CommandName == "Editar")
                {
                    Painel.Visible = true;
                    Session["oper"] = "Editar";
                    txEditar.Text = GridView1.Rows[int.Parse(e.CommandArgument.ToString())].Cells[0].Text;
                }
                else
                {
                    DLGenerica.Instance.apagarCategoria((int)Session["id_categoria"]);
                    Response.Write("<script>location.reload();</script>");
                }
            //}
        }

        protected void btAdicionar_Click(object sender, EventArgs e)
        {
            Painel.Visible = true;
            Session["oper"] = "Adicionar";
        }

        protected void btGravar_Click(object sender, EventArgs e)
        {
            if (Session["oper"] == "Adicionar")
            {
                DLGenerica.Instance.adicionarCategoria(txEditar.Text);
            }
            else
            {
                DLGenerica.Instance.editarCategoria((int)Session["id_categoria"] ,txEditar.Text);
            }
            Painel.Visible = false;
            Response.Write("<script>location.reload();</script>");
        }
    }
}